<?php
include "sql.php";
$ID=$_GET['proposal_id'];
// $prev_type=$_GET['type'];
$sql="select * from proposal_main where ID='$ID'";
$result=SQL_query($sql);
while($row=mysql_fetch_array($result))
    $arr[]=$row;
$arr=$arr[0];
//得到刚加载网页时的初始赞数：
$sql2="select * from  proposal_main where ID='$ID'";
$arr2=SQL_query($sql2);  
$arr2=mysql_fetch_array($arr2);
$praise_init=$arr2['praise'];
?>
<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
		<link rel="stylesheet" type="text/css" href="../css/stylesheet.css">
		<title>权小益·<?php echo $arr['title'];?></title>
        <script type="text/javascript" src="jquery.min.js"></script>
        <script type="text/javascript" src="star.js"></script>
        <script type="text/javascript">
        //刚加载网页时加载5条评论及评论平均分：
        LoadComments(1);
       var flag_praised=false;
       function OnPraise(){
        if(!flag_praised){
             $.post("ajax_praise.php",{"proposal_id":<?php echo $ID;?>},//$.post("url",{参数1名称:值1,参数2名称:值2，...},
                 function(data){
                  //后台使用了json_encode函数，所以前台不需要用var data=eval_r(“(”+data+”)”);转换，如果有就会报错
                  document.getElementById('id_praise').innerHTML ="已赞("+data.now_praise_num+")";
                 },"json");
            flag_praised=true;
            }
        }
        var pages_num=0;
        var page_current=1;
        function LoadComments(page){
            $.post("ajax_get_comments.php",{"proposal_id":<?php echo $ID;?>,"page":page},
                function(data){   
                    //加载平均评分 average_score
                    document.getElementById('average_score').innerHTML=data.average_score+"分";
                    var comment_list_title=document.getElementById('comment_list_title');//评论：(第1&frasl;1页 共_条)
                    var id_comment_list=document.getElementById("id_comment_list");
                    pages_num=parseInt (data.comments_num/5);
                    if(data.comments_num%5!=0)pages_num++;
                    page_current=page;//成功返回加载5条评论后，将page存入全局变量page_current
                   if(data.comments_num==0||data.comments_num==null){
                     id_comment_list.innerHTML='';
                    comment_list_title.innerHTML="评论：(第0/0页 共0条)"; 
                    return;
                   } 
                    
                    comment_list_title.innerHTML="评论：(第"+page+"/"+pages_num+"页 共"+data.comments_num+"条)";
                    
                    //生成评论列表：
                  
                   id_comment_list.innerHTML='';
                  for(var i=0;i<5;i++){
                    if(data.comments_array[i].score==null||data.comments_array[i].time==null)continue;
                    id_comment_list.innerHTML=id_comment_list.innerHTML+"<li>"+data.comments_array[i].score+"分   评论时间"+data.comments_array[i].time+"</br>     "+data.comments_array[i].content+"</li>";
                 }
                 // alert(data.comments_array[1].score);

                },"json");
        }
        function OnComment(){
            // alert(form_starNum);
            $content_temp=document.getElementById('comment_content').value;
            if($content_temp==''){return;}
             $.post("ajax_comment.php",{"proposal_id":<?php echo $ID;?>,"score":form_starNum,'content':$content_temp},
                 function(data){
                    // alert('评论成功'+data);
                    LoadComments(1);
                    document.getElementById('comment_content').value='';
                 },"json");
        
        }
    function OnPrevPage(){
        if(page_current>1){
            LoadComments(page_current-1);
        }
    }
    function OnNextPage(){
        if(page_current<pages_num){
            LoadComments(page_current+1);
        }
    }
        </script>
	</head>
	<body>
		<div class="header">
			<a href="../index.html"><img src="../img/newhead.jpg"></a>
		</div>
		<div class="clear"></div>
        
                            <!-- <div  class="inputcom"> <input type='button' class="csubmit" value='返回'  sonclick="OnReturn();"></div> -->
		<!-- onClick="javascript :history.back(-1);"点击具体的文章时，需要把对应的信息从数据库中读取填到相应的html的位置 -->
		<div class="content"><!-- <div style="float:left;width:70%;">111</div> -->
        <div style="width:100%;height:1.5em;position:relative;">
              <a href="list.php?type=<?php echo $_GET['type'];?>&page=1"><div id="btn_return" class="good" style="cursor: pointer;float:right;margin:3px;">↰返回</div> </a>
              </div>
            <div class="title"><span>标题：<?php echo $arr['title'];?></span></div>
			<div class="intro"><span>内容：<?php echo $arr['content'];?></span></div>
			<div class="renew"><span>处理动态：<?php echo $arr['respond'];?></span></div>
			<!-- 需要统计点赞的人数 -->
			<div style="cursor: pointer;" id="id_praise" class="good" onclick="OnPraise();">赞(<?php echo $praise_init;?>)</div>
            <div class="title">平均评分：<span id="average_score"></span></div>
			<!-- 获得评分的分数并且可以进行平均分的计算 -->
            <!-- <form action='detail2.php' method='post'> -->

                <div class="score">
                <div style="line-height: 34px;height: 39px; float: left;">
                    <span>我要评分+评论：</span>
                </div>
                    <span>
        			<a onMouseOver="javascript:setProfix('environment_');showStars(1,'environment');" onMouseOut="javascript:setProfix('environment_');clearStars('environment');" href="javascript:setProfix('environment_');setStars(1,'environment');">
                        <img id="environment_1" title="差(1)" src="../img/icon_star_gold.png">
        			</a>
        
        			<a onMouseOver="javascript:setProfix('environment_');showStars(2,'environment');" onMouseOut="javascript:setProfix('environment_');clearStars('environment');"href="javascript:setProfix('environment_');setStars(2,'environment');">
         				<img id="environment_2" title="一般(2)" src="../img/icon_star_gold.png">
                    </a>
         
         			<a onMouseOver="javascript:setProfix('environment_');showStars(3,'environment');" onMouseOut="javascript:setProfix('environment_');clearStars('environment');"href="javascript:setProfix('environment_');setStars(3,'environment');">
        				<img id="environment_3" title="好(3)" src="../img/icon_star_gold.png">
                    </a>
         
         			<a onMouseOver="javascript:setProfix('environment_');showStars(4,'environment');" onMouseOut="javascript:setProfix('environment_');clearStars('environment');" href="javascript:setProfix('environment_');setStars(4,'environment');">
         				<img id="environment_4" title="很好(4)" src="../img/icon_star_gold.png">
                     </a>
         
        			<a onMouseOver="javascript:setProfix('environment_');showStars(5,'environment');" onMouseOut="javascript:setProfix('environment_');clearStars('environment');" href="javascript:setProfix('environment_');setStars(5,'environment');">
         				<img id="environment_5" title="非常好(5)" src="../img/icon_star_gold.png">
                    </a>
                    </span>
                </div>
            	<!-- <div class="starsub" onclick="OnStarSubmit();">提交</div> -->
            	<div class="inputcom">
                    <textarea name="content" id="comment_content" placeholder="请在此处输入您的评论(200字以内)" maxlength="200"></textarea>

                    <input type='button' class="csubmit" value='发表'  onclick="OnComment(); "style="color:#ffffff;">
            	</div>
            <!-- </form> -->
			<div class="clear"></div>
			<!-- 评论功能，在这里匿名显示发表过的评论 -->
			<div class="comment">
                <span id="comment_list_title">评论：</span>
				<ul id="id_comment_list">
					<li>评论加载中...</li>
				</ul>
			</div>
            <div class="changepage">
				<div class="page" id="prev_page" onclick="OnPrevPage();">&lt;&lt;Prev</div>
				<div class="page page2" id="next_page" onclick="OnNextPage();">Next&gt;&gt;</div>
			</div>
		</div>
		<div class="wholecori">
			<div class="copyright">
				<span>Copyright © 2017 华南理工大学学生会权益部</span>
			</div>
			<div class="copyright">
				<span>Power by 无线电爱好者协会信息部</span>
			</div>
		</div>
		<div class="clear"></div>
	</body>
</html>